/**
 * 出库信息后端
 */

package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.WmsCkManagement;
import com.qf.service.WmsCkManagementService;
import com.qf.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class WmsCkManagementController {


    @Autowired
    private WmsCkManagementService service;

    /**
     * 查询全部信息并且对这些信息进行分页查询
     *
     * @param map
     * @return
     */
    @GetMapping("/listAll")
    public R findAll(@RequestParam HashMap<String, String> map) {
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        // 1 先设置分页信息
        PageHelper.startPage(pageNum, pageSize);
        // 2 正常执行查询
        List<WmsCkManagement> wmsCkManagement = service.findAll(map);
        // 3 通过查询返回的list创建出分页信息,PageInfo内包含所有分页数据,可以点入源码查看
        PageInfo<WmsCkManagement> info = new PageInfo<>(wmsCkManagement);
        System.out.println("当前面" + info.getPageNum());
        System.out.println("页面大小" + info.getPageSize());
        System.out.println("总条数" + info.getTotal());
        System.out.println("总页数" + info.getPages());
        System.out.println("数据" + info.getList());
        return R.ok(info);
    }


    /**
     * 删除
     *
     * @param requestNum
     * @return
     */
    @GetMapping("/delcancelck")
    public R del(Long requestNum) {
        boolean isok = service.del(requestNum);
        return R.ok(isok);
    }


    /**
     * 添加 （~~~~~~~~~~~~~~）
     * @param wmsCkManagement
     * @return
     */
    @PostMapping("/add")
    public R add(WmsCkManagement wmsCkManagement) {
        boolean isok = service.add(wmsCkManagement);
        return R.ok(isok);
    }

    /**
     * 申请项目下拉框
     * @return
     */
    @GetMapping("/selectByProject")
    public R selectByProject() {
       List<WmsCkManagement> list = service.selectByProject();
       return R.ok(list);
    }

    /**
     * 申请人下拉框
     * @return
     */
    @GetMapping("/selectByName")
    public R selectByName() {
        List<WmsCkManagement> list = service.selectByName();
        return R.ok(list);
    }

    /**
     * 状态下拉框
     * @return
     */
    @GetMapping("/selectByStatus")
    public R selectByStatus(){
        List<WmsCkManagement> list = service.selectByStatus();
        return R.ok(list);
    }

}
